<!-- 新增、编辑、查看 -->
<template>
  <dt-modal-edit ref='edit' :title='title' :label-width='130' okText='保存'
    :cancelText="is_view?'关闭':'取消'" :width='60' @ok='onOk' :showOk='!is_view'
    class="dt_modal_edit">

  </dt-modal-edit>
</template>

<script>
  import housetypeMgr from '@/biz/housetype/housetype'
  import houseMgr from './opt/houseEdit'
  import carPortMgr from './opt/carPortEdit'
  import shopMgr from './opt/shopEdit'
  import officeEdit from './opt/officeEdit'
  export default {
    components: {},
    data() {
      return {
        title: '',
        is_view: false,
        info: {},
        saveType: ''
      };
    },
    methods: {
      create(data, type) {
        this.saveType = 'create'
        this.title = data.title
        this.is_view = false
        this.info = {
          type,
          houseTypeName: '', //户型名称
          salesStatus: '', //销售状态
          houseTypeComment: '', //户型点评
          houseTypeAnnex: [], //户型图
          bedroom: null, //室
          hall: null, //厅
          toilet: null, //卫
          orientation: '', //朝向
          decoration: '', //住宅/办公楼装修
          houseTypeTag: [], // 户型标签
          carportType: '', //车位类型
          chargingPile: '', //是否有充电桩(1: 有 2: 无)
          decorationCarport: '', //车位装修
          
          storyHeightOptions: 1, //层高
          storyHeightStart: null, //层高
          storyHeightEnd: null, //层高
          
          facadeWidthOptions: 1, //开间(门面宽度)
          facadeWidthStart: null, //开间(门面宽度)
          facadeWidthEnd: null, //开间(门面宽度)
          
          floorAreaOptions: 1, //建面
          floorAreaStart: null, //建面
          floorAreaEnd: null, //建面
          
          unitPriceOptions: 1, //单价
          unitPriceStart: null, //单价
          unitPriceEnd: null, //单价
          
          totalPriceOptions: 1, //总价
          totalPriceStart: null, //总价
          totalPriceEnd: null, //总价
          
          layerTwo: '', //是否允许搭建二层(1: 允许 2:不允许)
          floor: '', //楼层
          partitionIf: '', //是否可以分割(1: 可分割 2: 不可分割)
        }
        console.log(this.info)
        this.show(type)
      },
      edit(data, type) {
        this.saveType = 'edit'
        this.is_view = false
        this.title = data.title
        this.info = data
        console.log(data)
        this.show(type, 'editedit')
      },
      view(data, type) {
        this.title = data.title
        this.is_view = data.is_view
        this.info = data
        this.show(type)
      },
      show(type) {
        // console.log(document.querySelector('.ivu-modal-body .content .ivu-form'),
        //   document.querySelector('.ivu-modal-body .content .ivu-form'),
        //   '####')
        if (type == 'residence') {
          this.$refs.edit.show(houseMgr.options(this), this.info)
        } else if (type == 'stall') {
          this.$refs.edit.show(carPortMgr.options(this), this.info)
        } else if (type == 'shop') {
          this.$refs.edit.show(shopMgr.options(this), this.info)
        } else if (type == 'office') {
          this.$refs.edit.show(officeEdit.options(this), this.info)
        }
      },
      hide() {
        this.$refs.edit.hide()
        this.info = {}
      },
      onOk(data) {
        console.log('dataqqqqq')
        console.log(data, 'data')
        data.houseTypeTag = data.houseTypeTag.join(',')
        data.houseTypeAnnex = data.houseTypeAnnex ? JSON.stringify(data.houseTypeAnnex) : ''
        let params = {
          ...data,
        }
        console.log(params)
        if (this.saveType == 'create') {
          params.housesId = this.$dt.buildInfo().housesId
          housetypeMgr.saveHouseTypeInfo(params).then(res => {
            this.$emit('success')
            this.hide()
          })
        } else if (this.saveType == 'edit') {
          housetypeMgr.updateHouseTypeInfo(params).then(res => {
            this.$emit('success')
            this.hide()
          })
        }
      }
    }
  }
</script>
<style lang='scss' scoped>
  .dt_modal_edit {
    ::v-deep .ivu-modal-body {
      height: 650px;
      overflow: auto;
    }
  }
</style>